$(function(){
	
	//收货地址查询
	userAdress();
	var orderid = utilModule.getQueryString("orderid");
	function userAdress(){
		var param = {"userId":USERID};
		function callBackSlider(data){
			console.log(data);
			var html='';
			if(data.result==""){
				$(".receiving-list").empty();
			}
			for(i in data){
				html+= '<li v="'+data[i].id+'">'+data[i].address+data[i].houseNumber+'<p><span>'+data[i].consignee+'</span>'+data[i].mobile;
				if(data[i].isDefault=="1"){
					html+='<font class="default color_blue"><i class="iconfont icon-036"></i>设为默认地址</font></p>';
				}else{
					html+='<font class="default"><i class="iconfont icon-036"></i>设为默认地址</font></p>';
				}
				html+='<div class="delete"><i class="iconfont icon-025"></i></div></li>';
			}
			$(".receiving-list ul").append(html);
			var isCheck=$(".receiving-list ul li").attr("isdefault");
			if(isCheck=="1"){
				$(this).addClass("color_blue");
			}
		}
		onlineContinuationModule.userAdressSelect(param,callBackSlider);
	}
	
	//设为默认地址
	$(".receiving-list ul li .default").on("click",function(event){
		event.stopPropagation();
		$(this).addClass("color_blue");
		$(this).parent().parent().siblings().find(".default").removeClass("color_blue");
		var adressId=$(this).parent().parent().attr("v");
		var param = {"id":adressId,"isDefault":1}
		onlineContinuationModule.userAdressChange(param,callBackSlider);
		function callBackSlider(data){
			console.log(data);
			if(data.status==200||data ==1){
				mui.toast("保存成功"); 
			}else{
				mui.toast("保存失败");
			}
		}
	});
	
	//删除显示
	$(".receiving-title span").on("click",function(){
		$(".receiving-list .delete").toggle();
		$(".receiving-list .default").toggle();
	});
	//删除操作
	$(".receiving-list ul li .delete").on("click",function(event){
		event.stopPropagation();
		var adressId=$(this).parent().attr("v");
		var param = {"id":adressId}
		var btnArray = ['否', '是'];
		mui.confirm('您确定删除该地址吗？', '提示', btnArray, function(e) {
			if(e.index == 1) {
				onlineContinuationModule.userAdressDelate(param,callBackSlider);
				function callBackSlider(data){
					console.log(data);
					if(data.status==200||data ==1){
						mui.toast("删除成功"); 
						location.reload(false);
					}else{
						mui.toast("删除失败"); 
					}
				}
			}
		})
	});
	
	$(".receiving-addBot").on("click",function(){
		location.replace("../../html/onlineContinuation/receiving-address.html?orderid="+orderid);
	});
	
	$(".receiving-list ul li").on("click",function(event){
		event.stopPropagation();
		var addr_id = $(this).attr("v");
		sessionStorage.setItem("adressId",JSON.stringify(addr_id));
		location.replace("../../html/onlineContinuation/drug-delivery.html?id="+orderid);
	});
});
